<template>
	<div>
		<div v-if="accuseStatus!=1">
			<el-form ref="form" :model="form" label-width="300px">
				<el-form-item label="投诉原因(请谨慎如实填写,提交后不可修改):">
					<el-input v-model="accuseReason"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit">立即投诉</el-button>
					<el-button>取消</el-button>
				</el-form-item>
			</el-form>
		</div>
		<div v-if="accuseStatus==1">
			<template>
				<el-table :data="handlingResults" stripe style="width: 100%">
					<el-table-column prop="accuseReason" label="投诉原因" width="180">
					</el-table-column>
					<el-table-column prop="accuserResultDes" label="投诉处理结果" width="180">
					</el-table-column>
					<el-table-column prop="beginTime" label="开始时间" width="180">
					</el-table-column>
					<el-table-column prop="endTime" label="结束时间" width="180">
					</el-table-column>
				</el-table>
			</template>
		</div>
	</div>
</template>

<script>
	import $ from "jquery"
	export default{
		data() {
			return {
				accuseReason: '',
				orderId: this.$route.params.orderId,
				accuseStatus: this.$route.params.accuseStatus,
				handlingResults: [],
			};
		},
		methods: {
			onSubmit: function() {
				var _this = this;
				$.ajax({
					url: "http://localhost:80/feedback/orderComplaints",
					type: "get",
					data: {
						orderId: _this.orderId,
						accuseReason: _this.accuseReason,
					},
					headers: {
						"Access-Token": sessionStorage.getItem("Access-Token")
					},
					success: function(data) {
						alert("投诉成功！");
						_this.accuseStatus = '1';
						_this.getAccuseInfo();
						window.reload();
					},
					error: function(data) {
						alert(data.responseJSON.message);
					}
				});
			},
			getAccuseInfo: function() {
				var _this = this;
				$.ajax({
					url: "http://localhost:80/feedback/getHandlingResults",
					type: "get",
					data: {
						orderId: _this.orderId,
					},
					headers: {
						"Access-Token": sessionStorage.getItem("Access-Token")
					},
					success: function(data) {
						_this.handlingResults.push( data.res);
					},
					error: function(data) {
						console.log(data.responseJSON.message);
					}
				});
			}
		},
		mounted() {
			if(this.accuseStatus!=null){
				this.getAccuseInfo();
			}
		},
	}
</script>

<style>

</style>
